﻿using DBLayer;
using DBLayer.Datacontext;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ModelLayer;

namespace CtrLayer
{
    /// <summary>
    /// Author: Anders^2
    /// </summary>
    public class CtrLogin : ICtrLogin
    {
        public int ValidateLogin(string email, string password)
        {
            //default is null!
            CtrUser ctrUser = new CtrUser();
            int result = 1;
            var dbUser = ctrUser.GetUser(email, password);

            //if dbUser is null, then the combination of email && password was not available in the db
            if (dbUser == null)
            {
                result = -1;
            }
            
            //The dbUser must be an active user
            else if (dbUser.CurrentStatus != User.Status.Active)
            {
                result = -2;
            }
            
            return result;
        }
    }
}